package net.huashitong.ssydt.provider.money.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.money.entity.SsMoneyVipBag;
import net.huashitong.ssydt.money.entity.vo.SsMoneyVipBagInVO;
import net.huashitong.ssydt.money.entity.vo.SsMoneyVipBagQueryInVO;
import net.huashitong.ssydt.provider.money.service.SsMoneyVipBagService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.08.14
 */
@Api(value = "/money/vip/bags",tags = {"vip套餐包（后台）"})
@RestController
@RequestMapping("/money/vip/bags")
public class SsMoneyVipBagController {
    @Autowired
    private SsMoneyVipBagService ssMoneyVipBagService;

    @ApiOperation(value="新增vip套餐包", notes="根据传入条件新增记录")
    @PostMapping
    public Result<String> post(@Valid @RequestBody SsMoneyVipBagInVO ssMoneyVipBagInVO){
        SsMoneyVipBag ssMoneyVipBag = new SsMoneyVipBag();
        BeanUtils.copyProperties(ssMoneyVipBagInVO, ssMoneyVipBag);
        ssMoneyVipBagService.insert(ssMoneyVipBag);
        return ResultUtils.getSuccessResults();
    }

    @ApiOperation(value = "vip套餐包列表" , notes = "vip套餐包列表")
    @GetMapping
    public Result<PaginationResult<SsMoneyVipBag>> getList(@ModelAttribute SsMoneyVipBagQueryInVO ssMoneyVipBagQueryInVO){
        return ResultUtils.getSuccessResults(ssMoneyVipBagService.paginationQuery(ssMoneyVipBagQueryInVO));
    }

    @ApiOperation(value="获取vip套餐", notes="根据id取对象")
    @GetMapping("/{bagsId}")
    public Result<SsMoneyVipBag> get(
            @ApiParam(required = true, value = "套餐包id") @PathVariable("bagsId") Long bagsId){
        return ResultUtils.getSuccessResults(ssMoneyVipBagService.getById(bagsId));
    }

    @ApiOperation(value="修改vip套餐", notes="根据传入条件修改信息")
    @PutMapping("/{bagsId}")
    public Result<String> put(
            @ApiParam(required = true, value = "套餐包id") @PathVariable("bagsId") Long bagsId,
            @Valid @RequestBody SsMoneyVipBagInVO ssMoneyVipBagInVO){
        SsMoneyVipBag ssMoneyVipBag = new SsMoneyVipBag();
        BeanUtils.copyProperties(ssMoneyVipBagInVO, ssMoneyVipBag);
        ssMoneyVipBag.setId(bagsId);
        ssMoneyVipBagService.updateById(ssMoneyVipBag);
        return ResultUtils.getSuccessResults();
    }


    @ApiOperation(value="删除vip套餐", notes="根据id删除对象")
    @DeleteMapping("/{bagsId}")
    public Result<String> delete(
            @ApiParam(required = true, value = "套餐包id") @PathVariable("bagsId") Long bagsId){
        ssMoneyVipBagService.deleteById(bagsId);
        return ResultUtils.getSuccessResults();
    }

}
